/**
 * Created by Wing on 2017/6/8.
 */


// 获取今天学习情况
$.ajax({
    url: "/memorypalace/card/todaystudystatus.action",
    dataType: "json",
    success: function (statu) {

        var todayStatu = new Vue({
            el: "#todayStatu",
            data: statu,
            computed:{
                minutesOrSeconds:function () {
                    if(this.spendTime > 60){
                        return parseInt(this.spendTime/60);
                    }else{
                        return 0;
                    }
                }
            }
        });
    },
    error: function (error) {
        alert(error);
    }
});
// 图表
var historyChart;
// 加载图表
$(function () {
    FusionCharts.ready(function () {
        historyChart = new FusionCharts({
            "type": "column2d",
            "renderAt": "historyStatus_chart",
            "width": "521",
            "height": "220",
            "dataFormat": "json",
            "dataSource": {
                "chart": {
                    "caption": "Monthly revenue for last year",
                    "subCaption": "Harry's SuperMart",
                    "xAxisName": "Month",
                    "yAxisName": "Revenues (In USD)",
                    "yAxisNameFontSize": 12,
                    "formatNumber": 1,
                    "formatNumberScale": 0,
                    "showToolTip": 1,
                    "exportEnabled": 1,
                    "numDivLines": 5,
                    "theme": "fint",
                    "showBorder": "1",
                    "showPlotBorder": "1",
                    "plotBorderColor": "#fefa52",
                    "plotSpacePercent": 40,
                    "adjustDiv": 1
                },
                "data": [
                    {
                        "label": "Jan",
                        "value": "420000",
                        "color": "#fefa52"
                    },
                    {
                        "label": "Feb",
                        "value": "810000"
                    },
                    {
                        "label": "Mar",
                        "value": "720000"
                    },
                    {
                        "label": "Apr",
                        "value": "550000"
                    },
                    {
                        "label": "May",
                        "value": "910000"
                    },
                    {
                        "label": "Jun",
                        "value": "510000"
                    },
                    {
                        "label": "Jul",
                        "value": "680000"
                    },
                    {
                        "label": "Aug",
                        "value": "620000"
                    },
                    {
                        "label": "Sep",
                        "value": "610000"
                    },
                    {
                        "vLine": "true",
                        "label": "Appraisal",
                    },
                    {
                        "label": "Oct",
                        "value": "490000"
                    },
                    {
                        "label": "Nov",
                        "value": "900000"
                    },
                    {
                        "label": "Dec",
                        "value": "730000"
                    }
                ]
            }
        });
        historyChart.render();
        // 获取历史学习情况
        $.ajax({
            url: "/memorypalace/card/historystudystatus.action",
            success: function (statuList) {
                // console.log(statuList);
                var statuListArray = JSON.parse(statuList);
                var chart = {
                    "caption": "过去三十天的学习情况",
                    // "subCaption" : "Harry's SuperMart",
                    "xAxisName": "过去的第几天",
                    "yAxisName": "学习卡片的个数",
                    "yAxisNameFontSize": 12,
                    "formatNumber": 1,
                    "formatNumberScale": 0,
                    "showToolTip": 1,
                    "numDivLines": 5,
                    "theme": "fint",
                    "showBorder": "1",
                    "showPlotBorder": "1",
                    "plotBorderColor": "#fefa52",
                    "plotSpacePercent": 40,
                    "adjustDiv": 1
                }
                var data = [];
                $.each(statuListArray, function (i, statu) {
                    var map = {};
                    map["label"] = "" + statu.studyTimeDiff;
                    map["value"] = "" + (statu.studyNew + statu.studyReview);
                    data.push(map);
                });
                var jsonData = {chart: chart, data: data};
                historyChart.setJSONData(jsonData);
                historyChart.render();
            },
            error: function (error) {
                alert(error);
            }
        });
    })
});


// 最近学习
$.ajax({
    url: "/memorypalace/getrecentdeck.action",
    dataType: "json",
    success: function (decks) {
        var recent = new Vue({
            el: "#recent",
            data: {decks: decks}
        });
    },
    error: function (error) {
        console.log(error);
    }
});

// 学习难点
$.ajax({
    url:"/memorypalace/card/getdifficultcard.action",
    dataType:"json",
    success:function (cardList) {
        var list = [];
        $.each(cardList,function (i, card) {
            var noteTitle = JSON.parse(card.note.areaContents)[0];
            var cardStyleName = card.cardStyle.cardStyleName;
            list.push({noteTitle:noteTitle,cardStyleName:cardStyleName});
        })
        var defficultCard = new Vue({
            el:"#defficultCard",
            data:{cardList:list}
        });
    },
    error:function (error) {
        consol.log(error);
    }
});